package org.grapes.wine.api.server.method.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.grapes.wine.api.bean.GetCostomIntroductionBean;
import org.grapes.wine.api.bean.GetHotelInfoHotelIntroductionBean;
import org.grapes.wine.api.bean.MethodBean;
import org.grapes.wine.api.bean.ObjectFactory;
import org.grapes.wine.api.method.EWineMethod;
import org.grapes.wine.api.server.method.handler.RenderDocument;
import org.grapes.wine.api.server.model.DAOName;
import org.grapes.wine.api.server.model.dao.CostomDAO;
import org.grapes.wine.api.server.model.dao.HotelInfoDAO;
import org.grapes.wine.api.server.persistence.DAOOperate;
import org.w3c.dom.Document;

public class GetCostomIntroduction extends RenderDocument {

	static Logger logger = Logger.getLogger(GetCostomIntroduction.class);
	private static List param = new ArrayList();
	static {
		param.add("costomName");
	}

	public Document execute(HttpServletRequest request) throws Exception {
		boolean paramMatch = false;

		String costomName = request.getParameter("costomName");
		CostomDAO costomDAO = null;
		logger.info("costomName: " + costomName);
		List list = DAOOperate.queryList(DAOName.Costom);

		for (Iterator it = list.iterator(); it.hasNext();) {
			costomDAO = (CostomDAO) it.next();
			if (costomDAO.getCostomName().equals(costomName)) {
				paramMatch = true;
				break;
			}
		}

		if (paramMatch) {
			// put data input bean
			ObjectFactory factory = new ObjectFactory();
			GetCostomIntroductionBean bean = factory
					.createGetCostomIntroductionBean();
			bean.setCostomIntroduction(costomDAO.getIntroduction());
			MethodBean methodBean = new MethodBean();
			methodBean.setBean(bean);
			methodBean.setClazz(GetCostomIntroductionBean.class);
			return initDocumentByJAXB(methodBean);
		}
		return null;
	}

	public EWineMethod getMethodName() {
		return EWineMethod.GET_COSTOM_INTRODUCTION;
	}

	public List getParam() {
		return param;
	}
}
